package com.simple.space.util.excel;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 导出列定义
 */
public class ExcelColumn {

	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	private String name; // Excel列头显示名称
	private String fieldName; // 列数据取值字段
	private int width; // 列宽，默认为100
	private String style; // 列样式

	public ExcelColumn() {
	}

	public ExcelColumn(String name, String fieldName) {
		this.name = name;
		this.fieldName = fieldName;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	/**
	 * 列数据格式化,提供普通数据格式化，自定义是需重写该方法
	 * 
	 * @param obj
	 * @return
	 */
	public String format(Object obj) {
		if (obj == null) {
			return "";
		}
		// 提供数据转换接口
		if (obj instanceof Double) {
			return obj + "";
		}

		if (obj instanceof Float) {
			return ((Float) obj).intValue() + "";
		}

		if (obj instanceof Integer) {
			return ((Integer) obj).intValue() + "";
		}

		if (obj instanceof Long) {
			return ((Long) obj).intValue() + "";
		}

		if (obj instanceof Date) {
			return sdf.format(obj);
		}
		return (String) obj;
	}
}
